<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>로그인</title>
<%@ include file="/common/comm.jsp"%>
<script>
	function init() {
		$('.submitButton').on('click', function() {
			var url = '${initParam.base_path}/login.action?method=login';
			var id = $('input[name=id]').val();
			var password = $('input[name=password]').val();

			$.post(url, {
				'id' : id,
				'password' : password
			}, function(resp) {

				//var json = eval('(' + resp.responseText + ')');
				//var json = eval('(' + resp + ')');
				var json = resp;

				if (json.success) {
					alert("성공");
					//화면을 한번 갱신해 준다
					document.location.reload();
				} else {
					alert(json.reason);
				}
			});

			return false;
		});

		$('.check').on('click', function() {
			var url = '${initParam.base_path}/login.action?method=check';

			$.post(url, {}, function(resp) {
				var json = resp;

				if (json.success) {
					alert(json.list[0].name);
				} else {
					alert(json.reason);
				}
			});
		});

		$('.logout').on('click', function() {
			var url = '${initParam.base_path}/login.action?method=logout';

			$.post(url, {}, function(resp) {
				document.location.reload();
			});
		});
	}
</script>
</head>
<body>
	<div class="loginBox">
		<form class="login" name="login" method="POST">
			<input type="text" name="id"> 아이디 <br> <input
				type="text" name="password"> 비밀번호 <br> <input
				class="submitButton" type="submit" />
		</form>
		<a href="${initParam.base_path}/jsp/user/user.jsp">계정추가</a>
		<button class="check">세션체크</button>
		<br>
		<button class="logout">로그아웃</button>
	</div>
</body>
</html>